﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twodi.Behavior.Interfaces;
using Microsoft.Xna.Framework;
using Twodi.Aspect.Interfaces;
using Twodi.Interfaces;
using Twodi.Aspect.Implemented;

namespace Twodi.Behavior.Implemented
{
    /// <summary>
    /// Comportamento responsavel por acelerar um componente.
    /// </summary>
    public class AccelerationBehavior : AbstractBehavior<IAccelerationBehavior>, IAccelerationAspect
    {
        /// <summary>
        /// Construtor padrão.
        /// </summary>
        /// <param name="component"></param>
        public AccelerationBehavior(IAccelerationBehavior component)
            : base(component)
        {
            AccelerationProperties = new AccelerationAspect();
        }

        public override void Initialize()
        {
            return;
        }

        /// <summary>
        /// Logica de update da aceleração, aonde é calculado a velocidade levando em consideração o gameTime e acrescentada a velocidade na posição do componente.
        /// </summary>
        /// <param name="gameTime">Tempo atual do jogo.</param>
        public override void Update(GameTime gameTime)
        {
            if (this.AccelerationProperties.Acceleration != Vector2.Zero)
            {
                this.Velocity += Vector2.Multiply(this.Acceleration, (float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            if (this.AccelerationProperties.Velocity != Vector2.Zero)
            {
                this.Component.PositionProperties.Position += this.Velocity;
            }
        }

        public override void Draw(GameTime gameTime)
        {
            return;
        }

        public override bool Handle(Input.KeyboardInput input)
        {
            throw new NotImplementedException();
        }

        public override bool Handle(Input.MouseInput input)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Aceleração do componente.
        /// </summary>
        public Vector2 Acceleration
        {
            get
            {
                return this.AccelerationProperties.Acceleration;
            }
            set
            {
                this.AccelerationProperties.Acceleration = value;
            }
        }

        /// <summary>
        /// Velocidade do componente.
        /// </summary>
        public Vector2 Velocity
        {
            get
            {
                return this.AccelerationProperties.Velocity;
            }
            set
            {
                this.AccelerationProperties.Velocity = value;
            }
        }

        public IAcceleration AccelerationProperties
        {
            get;
            set;
        }
    }
}
